package leetcode;

public class longestCommonPrefix {

    public String longestCommonPrefix(String[] strs){
        StringBuilder builder = new StringBuilder();
        int i = 0;
        try{
            while(i < strs[0].length()){
                char curr = strs[0].charAt(i);
                boolean flag = true;
                for(int j = 1; j < strs.length; j++){
                    char that = strs[j].charAt(i);
                    if(that != curr){
                        flag = false;
                        break;
                    }
                }
                if(!flag){
                    break;
                }else{
                    builder.append(curr);
                    i++;
                }
            }
        }catch (Exception e){

        }
        return builder.toString();
    }

}
